package editor.menu;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import applet.resource.Sprite0D;


/** An item in a JumpList. */
public class Item extends JumpListItem {
	/** */
	static final int ICON_X = 8;
	/** */
	static final int ICON_Y = 4;
	/** */
	static final int TEXT_X = 32;
	/** */
	static final int TEXT_Y = 16;
	/** */
	public static final int WIDTH = 96;
	/** */
	public static final int HEIGHT = 24;

	/** */
	static final Font FONT;
	static {
		final String fontName = "Consolas";
		final int fontStyle = Font.BOLD;
		final int fontSize = 16;
		FONT = new Font(fontName, fontStyle, fontSize);
	}

	/** */
	static final int TEXT_LENGTH = 6;

	/** */
	private String name;
	/** */
	private String text;
	/** */
	private Sprite0D icon;

	/**
	 * @param newName
	 *            - the text name of this item.
	 */
	public Item(final String newName) {
		name = newName;
		text = name.substring(0, Math.min(TEXT_LENGTH, name.length()));
		String file = name.toLowerCase().replace(' ', '-');
		icon = new Sprite0D("editor/icons/" + file + ".png");
	}

	/** @return the name of this item. */
	public final String getName() {
		return name;
	}

	/** @return the text. */
	public final String getText() {
		return text;
	}

	/** @return the label. */
	public final Sprite0D getIcon() {
		return icon;
	}

	/**
	 * @param g
	 *            - the graphics context to draw to.
	 * @param x
	 *            - the horizontal position in pixels.
	 * @param y
	 *            - the vertical position in pixels.
	 */
	public final void draw(final Graphics g, final int x, final int y) {
		icon.draw(g, x + ICON_X, y + ICON_Y);

		// TODO - Move this somewhere more general
		((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
				RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

		g.setColor(Color.BLACK);
		g.setFont(FONT);
		g.drawString(text, x + TEXT_X, y + TEXT_Y);
	}
}
